/* startup.c */

#include "ptpd.h"
#include "uc_log.h"
#include <rtthread.h>

PtpClock *ptpClock;

void ptpdShutdown()
{
    netShutdown(&ptpClock->netPath);

    free(ptpClock->foreign);
    free(ptpClock);

    TRACE_D("ptpdShutdown");
}

PtpClock *ptpdStartup(RunTimeOpts *rtOpts)
{
    ptpClock = (PtpClock *)rt_malloc(sizeof(PtpClock));
    if (!ptpClock)
    {
        TRACE_I("ptpClock malloc fail");
        return RT_NULL;
    }

    ptpClock->foreign = (ForeignMasterRecord *)rt_malloc(sizeof(ForeignMasterRecord));
    if (!ptpClock->foreign)
    {
        TRACE_I("ptpClock->foreign malloc fail");
        free(ptpClock);
        return RT_NULL;
    }

    rt_memset(ptpClock, 0, sizeof(PtpClock));

    return ptpClock;
}
